﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CRMSalesManagement.FrontPageShow
{
    public partial class WebIntent : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnPutIn_Click(object sender, EventArgs e)
        {
            if (this.txtDementInfor.Text.Trim() == "")
            {
                this.lblResult.Text = "需求简述不能为空";
                this.txtDementInfor.Focus();
            }
            else if (this.txtDementInfor.Text.Length > 200)
            {
                this.lblResult.Text = "需求简述不能超过200字";
                this.txtDementInfor.Focus();
            }
            else
            {
                this.lblResult.Text = "";
                if (this.txtCode.Text.Trim() == "")
                {
                    this.lbCode.Text = "请输入验证码";
                    this.txtCode.Focus();
                }
                else if (this.txtCode.Text.Trim().ToLower() == Request.Cookies["CheckCode"].Value.ToString().ToLower())
                {
                    this.lbCode.Text = "";
                    CRM.DataLayer.WebIntent webIntent = new CRM.DataLayer.WebIntent();
                    webIntent.name= this.txtName.Text.Trim();
                    webIntent.contact = this.txtContact.Text.Trim();
                    webIntent.dementInfor = this.txtDementInfor.Text.Trim();
                    webIntent.address = this.txtAddress.Text.Trim();
                    webIntent.title = this.txtTitle.Text.Trim();
                    webIntent.visitTime = DateTime.Now;
                    webIntent.isDispose = false;
                    bool addMessage = CRM.Business.WebIntent.AddWebIntent(webIntent);
                    if (!addMessage)
                    {
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('提交失败，请重新操作……');</script>"); 
                              
                    }
                    else
                    {
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('提交成功,我们将尽快与您联系，谢谢。');</script>"); 
                                          
                    }
                }
                else
                {
                    this.lbCode.Text = "验证码输入有误";
                    this.txtCode.Text = "";
                    this.txtCode.Focus();
                }
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            this.txtCode.Text = "";
            this.txtContact.Text = "";
            this.txtDementInfor.Text = "";
            this.txtName.Text = "";
            this.lbCode.Text = "";
            this.lblResult.Text = "";
        }
    }
}